﻿using System.Web.Mvc;
using Pottery.Frontend.Models;
using Pottery.Frontend.ViewModels;
using Softserve.Pottery.Store;
using Softserve.Pottery.Store.Domains;
using ServiceProvider = Softserve.Pottery.ServiceLocator.ServiceLocator;

namespace Pottery.Frontend.Controllers
{
    public class ProductController : Controller
    {
        /// <summary>
        /// Get and show all catalogs
        /// </summary>
        /// <returns>Object of ActionResult type</returns>
        public ActionResult Index()
        {
            //var model = CatalogsViewModel.FromDomainModel(m_CatalogRepository.GetCatalogs());
            var model = CatalogsViewModel.FromDomainModel(Mocks.catalogs);

            return View(model);
        }

        /// <summary>
        /// Method for parsing of url
        /// </summary>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        public ActionResult ReturnToUrl(string returnUrl)
        {
            return RedirectToAction("Index");
        }

        /// <summary>
        /// Get and show all products in some catalogs
        /// </summary>
        /// <param name="catalogId">Category Id</param>
        /// <returns>Object of ActionResult type</returns>
        public ActionResult ViewProducts(int catalogId = 0)
        {
            /*IEnumerable<Product> products = catalogId == 0
                                                ? m_StoreModule.GetProducts()
                                                : m_StoreModule.GetProductsByCatalogId(catalogId);

            var model = ProductsViewModel.FromDomainModel(products, m_StoreModule.GetCatalogs());*/
            
            var model = ProductsViewModel.FromDomainModel(Mocks.products, Mocks.catalogs);

            return View(model);
        }
        
        /// <summary>
        /// View product's details
        /// </summary>
        /// <param name="productId">Product Id</param>
        /// <returns>Object of ActionResult type</returns>
        public ActionResult ViewProductDetails(int productId)
        {
            ProductDetailsViewModel viewModel = new ProductDetailsViewModel();
            //viewModel.Product = m_StoreModule.GetProductById(productId);

            viewModel.Product = Mocks.product;

            return View(viewModel);
        }
        
        private IStoreScopeContract m_StoreModule = ServiceLocator.GetService(typeof(IStoreScopeContract)) as IStoreScopeContract;
        private static readonly ServiceProvider ServiceLocator = ServiceProvider.CreateInstance;
    }
}
